package com.datang.litejvm.engin;

import com.datang.litejvm.clz.Method;

/**
 * @author: 顶风少年
 * @Description: 执行结果
 * @date: 17:29 2022/6/16
 **/
public class ExecutionResult {
    //默认值 执行下一条指令
    public static final int RUN_NEXT_CMD = 1;
    //跳转指令
    public static final int JUMP = 2;
    //退出当前栈帧,剩余指令不执行了
    public static final int EXIT_CURRENT_FRAME = 3;
    //暂停当前栈帧,执行新的函数栈帧
    public static final int PAUSE_AND_RUN_NEW_FRAME = 4;

    //下一次的行为
    private int nextAction = RUN_NEXT_CMD;

    //如果是跳转指令 JUMP ,则会记录下一个指令偏移量
    private int nextCmdOffset = 0;

    //如果是执行新的栈帧 EXIT_CURRENT_FRAME 则需要设置栈帧对应的方法
    private Method nextMethod;

    /**
     * @author: 顶风少年
     * @Description: 获取下一个执行的方法
     * @date: 17:46 2022/6/16
     **/
    public Method getNextMethod() {
        return nextMethod;
    }

    public void setNextMethod(Method nextMethod) {
        this.nextMethod = nextMethod;
    }

    /**
     * @author: 顶风少年
     * @Description: 设置字节码执行后的行为, 默认为 RUN_NEXT_CMD 执行下一条指令
     * @date: 17:31 2022/6/16
     **/
    public void setNextAction(int action) {
        this.nextAction = action;
    }

    /**
     * @author: 顶风少年
     * @Description: 下一个字节码指令偏移量
     * @date: 17:43 2022/6/16
     **/
    public int getNextCmdOffset() {
        return nextCmdOffset;
    }

    public void setNextCmdOffset(int nextCmdOffset) {
        this.nextCmdOffset = nextCmdOffset;
    }


    /**
     * @author: 顶风少年
     * @Description: 执行结果
     * @date: 17:44 2022/6/16
     **/
    public boolean isPauseAndRunNewFrame() {
        return this.nextAction == PAUSE_AND_RUN_NEW_FRAME;
    }

    public boolean isExitCurrentFrame() {
        return this.nextAction == EXIT_CURRENT_FRAME;
    }

    public boolean isRunNextCmd() {
        return this.nextAction == RUN_NEXT_CMD;
    }

    public boolean isJump() {
        return this.nextAction == JUMP;
    }
}
